package com.example.shushiyunsst.fragment.main.home.child.icon_sst

import android.os.Bundle
import android.util.Log
import android.view.View
import android.webkit.JavascriptInterface
import android.webkit.WebView
import com.alibaba.fastjson.JSON
import com.example.library_common.base.BaseH5Fragment
import com.example.library_common.view.bottombar.BottomBorInfo
import com.example.shushiyunsst.BuildConfig
import com.example.wallet.db.UserInfoManager
import  com.example.shushiyunsst.R

class H5Fragment : BaseH5Fragment(), BottomBorInfo {

    companion object {
        fun newInstance(): H5Fragment {
            val args = Bundle()
            val fragment = H5Fragment()
            fragment.arguments = args
            return fragment
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mSuperBackPressedSupport=false
    }

    @JavascriptInterface
    fun getUserInfo(): String {
        val userInfo = UserInfoManager.userInfoManager.getUserInfoWrapper()
        Log.d("getUserInfo", "getUserInfo: ${JSON.toJSONString(userInfo)}")
        return JSON.toJSONString(userInfo)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mJssAdvancedWebView.loadUrl("file:///android_asset/sst/index.html")
    }

    @JavascriptInterface
    fun getDev(): String {
//        val userInfo = UserInfoManager.userInfoManager.getUserInfoWrapper()
//        Log.d("getUserInfo", "getUserInfo: ${JSON.toJSONString(userInfo)}")
        val dve =if(BuildConfig.DEBUG) 0 else 1
        val map = mapOf(
            "dve" to dve
        )
        return JSON.toJSONString(map)
    }

    override val title: Int = R.string.wallet_sst

    override val icon: Int = R.mipmap.icon_sst

    override fun refreshData() {

    }


    override fun shouldOverrideUrlLoadingPage(view: WebView?, url: String?): Boolean {
        Log.d("shouldOver", "shouldOverrideUrlLoadingPage: $url")
        return true
    }


}